# Maintainer: Ray Donnelly <mingw.android@gmail.com>

_realname=libimobiledevice
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=1.2.0
pkgrel=2
pkgdesc='A cross-platform protocol library to communicate with iOS devices (mingw-w64)'
arch=('any')
url='https://www.libimobiledevice.org/'
license=('GPL2+')
options=('staticlibs')
source=("https://www.libimobiledevice.org/downloads/${_realname}-${pkgver}.tar.bz2"
        001-cython-includes.patch
        0002-PyString_AsString-now-PyBytes_AsString.patch
        003-fix-py-soext.patch
        004-fix-ssl-link.patch)
depends=("${MINGW_PACKAGE_PREFIX}-libusbmuxd"
         "${MINGW_PACKAGE_PREFIX}-libplist"
         "${MINGW_PACKAGE_PREFIX}-openssl")
sha256sums=('786b0de0875053bf61b5531a86ae8119e320edab724fc62fe2150cc931f11037'
            '2e8b4ff6a571ab9109465a8556b96627e890c72b9e7956a3afa014cc7d89571b'
            '0e0ea6a31f563a8fff85a2247c3bc3440192cf554da58d689a0337084069e2e3'
            '50f073419ebcae49d2d2faef81715eec430817c3b1eeb4ce078f513738f2b85e'
            'b80e89ec15b59a71d8493c349d6d52362a1220d0ca6be2a9ce6c33f4b4f783bc')

prepare() {
  cd ${srcdir}/${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-cython-includes.patch
  patch -p1 -i ${srcdir}/0002-PyString_AsString-now-PyBytes_AsString.patch
  patch -p1 -i ${srcdir}/003-fix-py-soext.patch
  patch -p1 -i ${srcdir}/004-fix-ssl-link.patch

  autoreconf -fiv
}

build() {
  [[ -d "${srcdir}"/build-${CARCH} ]] && rm -rf "${srcdir}"/build-${CARCH}
  mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

  PYTHON=${MINGW_PREFIX}/bin/python \
  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --target=${MINGW_CHOST} \
    --enable-static \
    --enable-shared

  make
}

check() {
  cd "${srcdir}"/build-${CARCH}
  make check
}

package() {
  cd "${srcdir}"/build-${CARCH}
  make install DESTDIR="${pkgdir}"

  rm -f ${pkgdir}${MINGW_PREFIX}/lib/python*/site-packages/*.a
}
